<template>
  <div id="mTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="消息名称" prop="name">
          <el-input
            v-model="formInline.name"
            placeholder="请输出消息名称"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="消息类型" prop="messageTemplateAlias">
          <el-select
            v-model="formInline.messageTemplateAlias"
            clearable
            filterable
          >
            <el-option
              v-for="(item, index) in statusList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发送用户" prop="userType">
          <el-select v-model="formInline.userType" clearable filterable>
            <el-option
              v-for="(item, index) in userList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发送渠道" prop="sendType">
          <el-select v-model="formInline.sendType" clearable filterable>
            <el-option
              v-for="(item, index) in channeList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发送状态" prop="status">
          <el-select v-model="formInline.status" clearable filterable>
            <el-option
              v-for="(item, index) in postList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建人" prop="userId">
          <el-select v-model="formInline.userId" clearable filterable>
            <el-option
              v-for="item in creatersList"
              :key="item.userId"
              :label="item.trueName"
              :value="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset"> 重置 </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'
import { getUsers } from  '@/api/notice'
export default {
  name: 'mTopSearch',
  msg: '用户信息修改审核-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function () {
        return {
          endDate: '', // 创建结束时间
          messageTemplateAlias: '', // 消息类型
          name: '', // 消息名称
          sendType: '', // 发送渠道
          userId: '', //创建人
          startDate: '', // 创建开始时间
          status: '', // 发送状态
          userType: '', // 发送用户
          createTime: []//创建时间
        }
      },
    },
  },

  data() {
    return {
      loading: true,
      // 消息类型
      statusList: [
        // 消息类型
        { dictLabel: '全部', dictValue: '' },
      ],
      // 用户
      userList: [{ dictLabel: '全部', dictValue: '' }],
      // 渠道
      channeList: [{ dictLabel: '全部', dictValue: '' }],
      // 发送状态
      postList: [{ dictLabel: '全部', dictValue: '' }],
      orderList: [], //待审核排序列表
      verifyStatusList: [], // 人工审核状态列表
      verifyUserIdList: [{ nickname: '全部', dapengUserId: '' }], // 审核人列表
      creatersList: [], //所有创建人
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 获取数据状态 */
    // async getStatusList() {
    //   // 人工审核状态
    //   let data = await sysNormalDisable('send_status', 'send_status')
    //   this.verifyStatusList = this.statusList.concat(data)
    //   // 待审核排序
    //   let orderList = await sysNormalDisable('user_message_check_order')
    //   this.orderList = orderList
    //   this.setDefaultValue()
    //   //触发列表获取权限
    //   this.$emit('toSearch')
    // },
    /*设置默认数据*/
    // setDefaultValue() {
    //   this.formInline.order = this.orderList[1].dictValue
    //   this.formInline.verifyStatus = this.verifyStatusList[2].dictValue
    // },
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.verifyUserIdList = this.verifyUserIdList.concat(response)
      })
    },
    /* 获取字典状态 */
    async getStatusList() {
      let data = await sysNormalDisable(
        'operation_message_template_alias',
        'operation_message_template_alias'
      )
      this.statusList = this.statusList.concat(data)
      let dataUser = await sysNormalDisable(
        'notice_user_type',
        'notice_user_type'
      )
      this.userList = this.userList.concat(dataUser)
      let datachanneList = await sysNormalDisable('send_type', 'send_type')
      this.channeList = this.channeList.concat(datachanneList)
      let status = await sysNormalDisable('send_status', 'send_status')
      this.postList = this.postList.concat(status)
      //创建人查询数据
      let roles = [{ id: '311' },{ id: '301' },{ id: '296' },{ id: '292' },{ id: '236' },{ id: '257' }]
      // 创建人
      getUsers(roles, (response) => {
        this.creatersList = response
      })

    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      // this.setDefaultValue()
      // this.$emit('toSearch')
    },
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startDate = newVal[0]
          this.formInline.endDate = newVal[1]
        } else {
          this.formInline.startDate = ''
          this.formInline.endDate = ''
        }
      },
      deep: true
    }
  },
}
</script>

<style lang="less">
#mTopSearch {
  .long-input {
    .el-input--suffix {
      width: 130px !important;
    }
  }
}
</style>
